<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>numdifftools.core.Hessdiag</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="numdifftools-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://code.google.com/p/numdifftools/">numdifftools</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="numdifftools-module.html">Package&nbsp;numdifftools</a> ::
        <a href="numdifftools.core-module.html">Module&nbsp;core</a> ::
        Class&nbsp;Hessdiag
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="numdifftools.core.Hessdiag-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class Hessdiag</h1><p class="nomargin-top"><span class="codelink"><a href="numdifftools.core-pysrc.html#Hessdiag">source&nbsp;code</a></span></p>
<center>
<center>  <map id="uml_class_diagram_for_numdifft_3" name="uml_class_diagram_for_numdifft_3">
<area shape="rect" id="node1_4" href="numdifftools.core.Hessdiag-class.html#__doc__" title="numdifftools.core.Hessdiag.__doc__" alt="" coords="36,172,152,191"/>
<area shape="rect" id="node1_5" href="numdifftools.core.Hessdiag-class.html#__call__" title="numdifftools.core.Hessdiag.__call__" alt="" coords="36,193,152,212"/>
<area shape="rect" id="node1_6" href="numdifftools.core.Hessdiag-class.html#hessdiag" title="Diagonal elements of Hessian matrix" alt="" coords="36,212,152,231"/>
<area shape="rect" id="node1" href="numdifftools.core.Hessdiag-class.html" title="Estimate diagonal elements of Hessian of fun at x0, with error estimate" alt="" coords="23,147,163,237"/>
<area shape="rect" id="node3" href="numdifftools.core.Hessian-class.html" title="Estimate Hessian matrix, with error estimate" alt="" coords="53,257,137,295"/>
<area shape="rect" id="node2" href="numdifftools.core._PartialDerivative-class.html" title="numdifftools.core._PartialDerivative" alt="" coords="31,83,155,127"/>
<area shape="rect" id="node4_7" href="numdifftools.core._Derivative-class.html#__init__" title="x.__init__(...) initializes x; see help(type(x)) for signature" alt="" coords="17,39,171,57"/>
<area shape="rect" id="node4" href="numdifftools.core._Derivative-class.html" title="Object holding common variables and methods for the numdifftools" alt="" coords="5,6,182,63"/>
</map>
  <img src="uml_class_diagram_for_numdifft_3.gif" alt='' usemap="#uml_class_diagram_for_numdifft_3" ismap="ismap" class="graph-without-title" />
</center>
</center>
<hr />
<pre class="literalblock">
Estimate diagonal elements of Hessian of fun at x0,
with error estimate

Parameters
----------
fun : callable
    function to differentiate.
n : Integer from 1 to 4 defining derivative order.     (Default 1)
order : Integer from 1 to 4 defining order of basic method used.
        For 'central' methods, it must be from the set [2,4]. (Default 2)
method : Method of estimation.  Valid options are:
        'central', 'forward' or 'backward'.          (Default 'central')
romberg_terms : Number of Romberg terms used in the extrapolation.
        Must be an integer from 0 to 3.                       (Default 2)
        Note: 0 disables the Romberg step completely.
step_fix : If not None, it will define the maximum excursion from step_nom
             that is used and prevent the adaptive logic from working.
             This will be considerably faster, but not necessarily
             as accurate as allowing the adaptive logic to run.
            (Default: None)
step_max  : Maximum allowed excursion from step_nom as a multiple of it. (Default 4)
step_nom  : Nominal step.                          default maximum(x0, 0.02) 
step_ratio: Ratio used between sequential steps in the estimation
             of the derivative (Default 2)
        The steps used h_i = step_nom[i]*step_max*step_ratio**(-arange(steps_num))
step_num : integer
    if not specified it will be set according to the following rules: 
        step_num = 26 if step_fix is None
        step_num = 3.+ np.ceil(self.n/2.) + self.order + self.romberg_terms +4 otherwise
vectorized : True  - if your function is vectorized.
            False - loop over the successive function calls (default).

Uses a semi-adaptive scheme to provide the best estimate of the
derivative by its automatic choice of a differencing interval. It uses
finite difference approximations of various orders, coupled with a
generalized (multiple term) Romberg extrapolation. This also yields the
error estimate provided. See the document DERIVEST.pdf for more explanation
of the algorithms behind the parameters.

 Note on order: higher order methods will generally be more accurate,
         but may also suffer more from numerical problems. First order
         methods would usually not be recommended.
 Note on method: Central difference methods are usually the most accurate,
        but sometimes one can only allow evaluation in forward or backward
        direction.



HESSDIAG return a vector of second order partial derivatives of fun.
These are the diagonal elements of the Hessian matrix, evaluated
at x0.  When all that you want are the diagonal elements of the hessian
matrix, it will be more efficient to call HESSDIAG than HESSIAN.
HESSDIAG uses DERIVATIVE to provide both second derivative estimates
and error estimates.

Assumptions
------------
fun : SCALAR analytical function to differentiate.
    fun must be a function of the vector or array x0,
    but it needs not to be vectorized.

x0 : vector location at which to differentiate fun
    If x0 is an N x M array, then fun is assumed to be
    a function of N*M variables.

Examples
--------
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; import numdifftools as nd
&gt;&gt;&gt; fun = lambda x : x[0] + x[1]**2 + x[2]**3
&gt;&gt;&gt; ddfun = lambda x : np.asarray((0, 2, 6*x[2]))
&gt;&gt;&gt; Hfun = nd.Hessdiag(fun)
&gt;&gt;&gt; hd = Hfun([1,2,3]) # HD = [ 0,2,18]
&gt;&gt;&gt; hd
array([  0.,   2.,  18.])
&gt;&gt;&gt; np.abs(ddfun([1,2,3])-hd) &lt;= Hfun.error_estimate
array([ True,  True,  True], dtype=bool)


See also
--------
Gradient, Derivative, Hessian, Jacobian

</pre>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Instance Methods</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-InstanceMethods"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__call__"></a><span class="summary-sig-name">__call__</span>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">x00</span>)</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="numdifftools.core-pysrc.html#Hessdiag.__call__">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="numdifftools.core.Hessdiag-class.html#hessdiag" class="summary-sig-name">hessdiag</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">x00</span>)</span><br />
      Diagonal elements of Hessian matrix</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="numdifftools.core-pysrc.html#Hessdiag.hessdiag">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <div class="private">    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="numdifftools.core._PartialDerivative-class.html" onclick="show_private();">_PartialDerivative</a></code></b> (private):
      <code><a href="numdifftools.core._PartialDerivative-class.html#_fun" onclick="show_private();">_fun</a></code>,
      <code><a href="numdifftools.core._PartialDerivative-class.html#_partial_der" onclick="show_private();">_partial_der</a></code>
      </p></div>
    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="numdifftools.core._Derivative-class.html" onclick="show_private();">_Derivative</a></code></b>:
      <code><a href="numdifftools.core._Derivative-class.html#__init__">__init__</a></code>
      </p>
    <div class="private">    <p class="indent-wrapped-lines"><b>Inherited from <code><a href="numdifftools.core._Derivative-class.html" onclick="show_private();">_Derivative</a></code></b> (private):
      <code><a href="numdifftools.core._Derivative-class.html#_backward" onclick="show_private();">_backward</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_central" onclick="show_private();">_central</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_check_params" onclick="show_private();">_check_params</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_derivative" onclick="show_private();">_derivative</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_fda_mat" onclick="show_private();">_fda_mat</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_fder" onclick="show_private();">_fder</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_forward" onclick="show_private();">_forward</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_initialize" onclick="show_private();">_initialize</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_romb_extrap" onclick="show_private();">_romb_extrap</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_set_delta" onclick="show_private();">_set_delta</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_set_difference_function" onclick="show_private();">_set_difference_function</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_set_fda_rule" onclick="show_private();">_set_fda_rule</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_set_romb_qr" onclick="show_private();">_set_romb_qr</a></code>,
      <code><a href="numdifftools.core._Derivative-class.html#_trim_estimates" onclick="show_private();">_trim_estimates</a></code>
      </p></div>
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__format__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__new__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__repr__</code>,
      <code>__setattr__</code>,
      <code>__sizeof__</code>,
      <code>__str__</code>,
      <code>__subclasshook__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== CLASS VARIABLES ==================== -->
<a name="section-ClassVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="numdifftools.core.Hessdiag-class.html#_hessdiag_txt" class="summary-name" onclick="show_private();">_hessdiag_txt</a> = <code title="'''
    Parameters
    ----------
    fun : callable
        function to differentiate.
    n : Integer from 1 to 4 defining derivative order.     (Default 1)
    order : Integer from 1 to 4 defining order of basic method used.
            For \'central\' methods, it must be from the set [2,4]. (D\
..."><code class="variable-quote">'</code><code class="variable-string">\n    Parameters\n    ----------\n    fun : c</code><code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="numdifftools.core.Hessdiag-class.html#__doc__" class="summary-name">__doc__</a> = <code title="'''Estimate diagonal elements of Hessian of fun at x0,
    with error estimate
    '''+ _hessdiag_txt+ '''

    HESSDIAG return a vector of second order partial derivatives of fu\
n.
    These are the diagonal elements of the Hessian matrix, evaluated
    at x0.  When all that you want are the diagonal elements of the he\
...">'''Estimate diagonal elements of Hessian of fun at x<code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Properties</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Properties"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Method Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-MethodDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="hessdiag"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">hessdiag</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">x00</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="numdifftools.core-pysrc.html#Hessdiag.hessdiag">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Diagonal elements of Hessian matrix</p>
  <p>See also derivative, gradient, hessian, jacobian</p>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== CLASS VARIABLE DETAILS ==================== -->
<a name="section-ClassVariableDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Class Variable Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-ClassVariableDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="_hessdiag_txt"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">_hessdiag_txt</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
<code class="variable-quote">'''</code><code class="variable-string"></code>
<code class="variable-string">    Parameters</code>
<code class="variable-string">    ----------</code>
<code class="variable-string">    fun : callable</code>
<code class="variable-string">        function to differentiate.</code>
<code class="variable-string">    n : Integer from 1 to 4 defining derivative order.     (Default 1)</code>
<code class="variable-string">    order : Integer from 1 to 4 defining order of basic method used.</code>
<code class="variable-string">            For \'central\' methods, it must be from the set [2,4]. (D</code><span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
<code class="variable-ellipsis">...</code>
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<a name="__doc__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">__doc__</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
'''Estimate diagonal elements of Hessian of fun at x0,
    with error estimate
    '''+ _hessdiag_txt+ '''

    HESSDIAG return a vector of second order partial derivatives of fu<span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
n.
    These are the diagonal elements of the Hessian matrix, evaluated
    at x0.  When all that you want are the diagonal elements of the he<span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
<code class="variable-ellipsis">...</code>
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="numdifftools-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://code.google.com/p/numdifftools/">numdifftools</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Sat May 05 22:01:07 2012
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
